﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace BlogDH
{
    public partial class Index : System.Web.UI.Page
    {
        private int pageSize = CommValue.PageSize;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.GeBlogList();
            }
        }

        private void GeBlogList()
        {
            this.Literal1.Text = CommMethod.GetAreaHtml();

            int pageid = 1;
            if (!string.IsNullOrEmpty(Request.QueryString["pageid"]))
            {
                string pageidStr = Request.QueryString["pageid"].ToString();
                if (!int.TryParse(pageidStr, out pageid) || pageid == 0)
                    pageid = 1;
            }

            System.Data.DataSet ds = null;
            int totalCount = CommValue.HomeBlogListCount;

            if (pageid == 1)
            {
                //首页获取缓存数据
                ds = CommValue.HomeBlogList;
            }
            else
            {
                //读取数据库 
                ds = new BLL.BlogInfo().GetPageList(pageSize, pageid, totalCount, null);
            }

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.Repeater1.DataSource = ds;
                this.Repeater1.DataBind();
            }

            //设置分页
            if (totalCount > this.pageSize)
            {
                int totalPageCount = totalCount / this.pageSize;
                if (totalCount % this.pageSize > 0)
                    totalPageCount++;
                this.ltr_paging.Text = CommMethod.GetPaging(null, totalPageCount, pageid);
            }
        }

    }
}